/**
 * Created by smp on 2017/6/5.
 */
var modelPath=ROOT_PATH+'/archives/personArchives/safetyAssessmentRewardPunishmentLedger/';
$('#belongUnit').combotree({
    url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0'
});
$('#examineDept').combotree({
    url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0'
});
$('#checkedDept').combotree({
    url: ROOT_PATH+'/permission/department/getDepartmentTree.shtml?parentId=0'
});
var getSelectedUser = function (data) {
    var id=data[0].id;
    var realName=data[0].realName;
    $("#checkedPerson").val(id);
    $("#checkedPersonName").textbox("setValue",realName);

};

$('#checkedPersonName').textbox({
    required: true,
    icons: [{
        iconCls: 'icon-search',
        handler: function () {
            WindowManager.openLayer({
                type: 2,
                title: '考核人',
                area: ['90%', '70%'],
                content: ROOT_PATH + '/permission/user/simpleList.shtml?isMulti=0',
                callBack:getSelectedUser
            });
        }
    }],
    editable: false
});
$("#btn_save").click(function(){
    var index=layer.confirm('是否确定保存？', {
        btn: ['确定','取消'] //按钮
    }, function(){
        var isValid = $('#form1').form('validate');
        if (!isValid) {
            layer.close(index);
            layer.msg("请正确填写表单")
        }
        var d = {};
        var t = $('#form1').serializeArray();
        $.each(t, function() {
            d[this.name] = this.value;
        });
        d["checkedDeptName"]=$('#checkedDept').combotree("getText");
        d["belongUnitName"]=$('#belongUnit').combotree("getText");
        d["examineDeptName"]=$('#examineDept').combotree("getText");
        $.ajax({
            type:"post",
            url:modelPath+"updateRelation.shtml",
            data:d,
            success:function (data) {
                WindowManager.closeLayer({
                    returnValue: d
                });
            }
        });
    });

});
$("#isCheckPerson").combobox({
    onSelect:function(param){
        if(param.value==0){
            $("#block1").css('display','none');
            $("#block2").css('display','inline');
            $("#checkedDept").textbox({"required":true});
            $("#checkedPersonName").textbox({"required":false});

        }else {
            $("#block2").css('display','none');
            $("#block1").css('display','inline');
            $("#checkedDept").textbox({"required":false});
            $("#checkedPersonName").textbox({"required":true});
        }
    }
});
